package com.mcy.springbatch.writer;

import com.mcy.springbatch.entity.SysUser;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * 利用JdbcBatchItemWriter把数据写到数据库
 * @author : Create By mcy
 * @date : 2019/8/25 15:33:18
 */
@Component
public class SysUserJdbcBatchItemWriter extends JdbcBatchItemWriter<SysUser> {

    @Autowired
    DataSource dataSource;

    @PostConstruct
    public void init(){
        setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<SysUser>());
        setSql("insert into sys_user(login_name,user_name,id_card,phone,sex,address,email,status) values(:loginName,:userName,:idCard,:phone,:sex,:address,:email,:status)");
        setDataSource(dataSource);
    }
}
